package net.huashitong.Indicators.app;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.util.SysUserUtils;
import com.sirdc.modules.utils.ObjectUtils;
import net.huashitong.Indicators.entity.FeedBack;
import net.huashitong.Indicators.entity.UserInfo;
import net.huashitong.Indicators.filter.FeedBackFilter;
import net.huashitong.Indicators.service.FeedBackService;
import net.huashitong.Indicators.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/app/feedback")
public class FeedBackController extends JsonBaseController {
    @Autowired
    private FeedBackService feedBackService;
    @Autowired
    private UserInfoService userInfoService;

    @Override
    protected String getView(String s) {
        return null;
    }

    @ResponseBody
    @RequestMapping(value = "/addFeedBack",method = RequestMethod.POST)
    public Message addFeedBack(@RequestBody FeedBackFilter feedBackFilter){
//        String userid = SysUserUtils.getUserId();
        UserInfo userInfo = userInfoService.getById(feedBackFilter.getUserId());
        FeedBack feedBack = new FeedBack();
        if(ObjectUtils.isNotBlank(userInfo)){
            feedBack.setUserId(userInfo.getUserId());
        }else{
            feedBack.setUserId("");
        }
        feedBack.setOpinion(feedBackFilter.getOpinion());
        feedBack.setEmail(feedBackFilter.getEmail());
        feedBack.setPhone(feedBackFilter.getPhone());
        feedBackService.save(feedBack);
        return coverMessage("200","提交成功");
    }
}
